\Wbegin[]{article{1em{1em{f_to_web.cts{{\&{\|{\\{\\{\\{\@}{\.}{\.

% — Beginning of user’s limbo section —

\def\title{— F\_TO\_WEB —

\WN1. INTRODUCTION. This demo shows you how to convert the file \.{f\_to\_web.src (look at that file with your editor now) into a valid \.{FWEB file, namely this file \.{f\_to\_web.web. Each subroutine should be placed into a separate module, begun with~‘\.{
’ or~‘\.{@\ ’. After those symbols, you should explain what the subroutine does, using \TeX\ in all its glory. Then follows the code, introduced by~‘\.{@a’ or ‘\.{@<...@>=’. Code sections should be short—about 12 lines, according to Knuth. If they’re too long, break them up into named fragments that are explained separately. For new code, comments should be C-style—namely, “\.{/*...*/” or “\.{//...”. (In order to use the latter form, you must use the command-line option~‘\.{-n/’, and then you must use the symbol~‘\.{\\/’ for concatenation.)

Before proceeding, let us note that standard Fortran is {\it not recommended for new code. Use the Ratfor mode instead. Standard Fortran mode is intended primarily to support conversion of existing code.

Notice how forward references to named modules and function names are handled in the woven output. \WY\WP \&{program \1\\{main\WIN1{0\2\1\6 \WX2:Common blocks\X \X\1\2\7 \WC{ Initialize values. Long comments should be done in standard C style and may be continued across lines. \7 ${\|x={-\WO{3.14159\^E-11$\6 ${\|i=\WO{1{$\7 \&{call \\{see\WIN1{3\5 \Wc{ Print results. (Short comments can be done like this.)\2\7 \&{end\WY\par \fi % End of module 1

\WM2. Code fragments can be defined anywhere, even after they are used.

\WY\WP\WF::\WX2:Common blocks\X \X\ \\{common\5 \WC{ Use a format statement to tell \.{WEAVE how to handle this module name. % \WY\par \WY\WP\4\4\WX2:Common blocks\X \X${\WS{$\6 \&{integer \1\|i\2\6 \&{real \1\|x\2\6 \&{common \1 ${{/\\{test{/$ \|x, \|i\2\WY\par \WU sections~1 and~3.\fi % End of module 2

\WM3. Notice how the common block information is handled. You don’t need to include such stuff from a separate file.

\WY\WP\WMD$\\{NFMT$\5 \NC $\WO{0{$\5 \WC{ This preprocessor command is a handy way of replacing numeric statement labels by symbolic ones. Numeric statement labels will never have to be used. % \WY\par \WY\WP \&{subroutine \1\\{see\WIN1{0\2\1\6 \WX2:Common blocks\X \X\1\2\5 \WC{ You can abbreviate the name if it has already appeared in full. \7 ${\&{write\,(\WO{6,\39\\{NFMT)$ \|x, \|i\6 \llap{\\{NFMT\Colon\ ${\&{format\,(\.{’\ x\ =\ ’,\39\WO{1\\{pe10.2,\39% \.{’\1\ i\ =\ ’,\39\\{i2)$ ;\6 \&{return\2\6 \&{end\WY\par \fi % End of module 3

\WM4. In fact, the Ratfor language is recommended for new Fortran codes. It’s best to do everything in Ratfor, but you can also work on a module-by-module basis. Here’s an example. Examine the listing of the output file in Appendix~D to see how this is translated into standard Fortran.

\WY\WP \LANGUAGE{R\&{integer \&{function \1\|f\WIN1{0(\|a,\39\|b,\39\|n)\2% \1\1\6 \&{integer \1\|n;\2\2\2\1\1\6 \&{real \1\|a${(\WO{0:\|n-\WO{1),$ \|b${(\WO{0:\|n-\WO{1);$\2\2\2\1\6 ${\{$\6 \&{integer \1\|k;\2\7 \5 \WC{ You can (and should) use a \WCD{ \&{do loop for the following, but the % \WCD{ \&{for construction is more flexible in general, so we use it to demonstrate. \7 ${\&{for\,(\|k=\WO{0;$ ${\|k<\|n;$ ${\|k\PP)$ \1\6 ${\{$\6 ${\|a(\|k)=\|k;$\6 ${\|b(\|k)=\|k\EE{\WO{2;{$\5 \WC{ In Ratfor and Fortran, you can use pretty alternatives for archaic Fortran constructions such as~\.{.lt. or~\.{**. \6 ${\$\2\7 \&{return \|n;\5 \Wc{ It’s easy to return values from functions.\6 ${\$\2\WY\par \fi % End of module 4

\WN5. INDEX. \fi % End of module 5

\input f_to_web.ndx \input f_to_web.mds

\Winfo{"fweave ./f\_to\_web -zdemos.sty -=f\_to\_web.tex" {"./f\_to% \_web.web" {(none) {FORTRAN

\Wcon


This document was generated on January 31, 2023 using texi2html 5.0.